<?php
/**
 * Description of LeilaoService
 *
 * @author Magno
 */
class LeilaoService {


    private $leilaoDAO;
    function __construct() {
        $this->leilaoDAO = new LeilaoDAO();
    }


    public function salvar($leilao) {

        try {
            return $this->leilaoDAO->salvar($leilao);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }

    }

    public function excluir($leilaoID) {

        try {
            if(!isset ($leilaoID) || $leilaoID <= 0)
                throw new Exception("Codigo da Leilao Nao Econtrado!!!");

            $this->leilaoDAO->excluir($leilaoID);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }

    }

    public function listar($pagina = 0, $inicio = "", $tipoLeilaoID = -1, $cronometroID = -1, $statusID = -1, $usuarioID = -1, $carregarDependencias = false) {
        try {
            return $this->leilaoDAO->listar($pagina, $inicio, $tipoLeilaoID, $cronometroID, $statusID, $usuarioID, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function listarPorOrdem($pagina = 0, $tamanho = 0, $ordem = "leilaoID", $direcao = "DESC", $carregarDependencias = false) {
        try {
            return $this->leilaoDAO->listarPorOrdem($pagina, $tamanho, $ordem, $direcao, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function buscarPorID($leilaoID, $carregarDependencias = false) {
        try {
            if(!isset ($leilaoID) || $leilaoID <= 0)
                throw new Exception("Codigo da Leilao Nao Econtrado!!!");
            return $this->leilaoDAO->buscarPorID($leilaoID, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function total($inicio = "", $tipoLeilaoID = -1, $cronometroID = -1, $statusID = -1, $usuarioID = -1) {
        try {
            return $this->leilaoDAO->total($inicio, $tipoLeilaoID, $cronometroID, $statusID, $usuarioID);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }
}
?>
